<template>
	<view>
		<view class="setup-content">
			<u-gap height="30" bg-color="#f8f8f8"></u-gap>
			<view class="container">
				<view :class="[{'items':true,'noborder':true}]">
					<view class="label">线上咨询</view>
					<view class="val">
						<u-switch v-model="consultOpen" active-color="#0fcd87" inactive-value="关闭" active-value="开放"  @change="isOpen('线上咨询')"></u-switch>
					</view>
				</view>
			</view>
		</view>
		<view class="setup-content">
			<view class="container">
				<view  :class="[{'items':true,'noborder':false}]">
					<view class="label">线下会诊</view>
					<view class="val">
						<u-switch v-model="registerOpen" active-color="#0fcd87" inactive-value="关闭" active-value="开放"  @change="isOpen('线下会诊')"></u-switch>
					</view>
				</view>
			</view>
		</view> 
		<!-- 模态框  -->
		<authenModal v-show="isShow" @close="closeBtn" @confirm="confirmBtn" :content="content" :confirmText="confirmText"></authenModal>
	</view>
</template>

<script>
	import { API } from "@/config/myApi.js";
	import authenModal from "@/myComponents/modal/authen-modal.vue";
	export default {
		components: {
			authenModal,
		},
		data() {
			return {
				expertId: this.$store.state.expertId,
				// dataList:[
				// 	{
				// 		label: "线上咨询",
				// 		noborder:true,// 去掉边框
				// 	},
				// 	{
				// 		label: "线下会诊",
				// 		noborder:false,
				// 	}
				// ],
				consultOpen: false,
				registerOpen: false,
				// 模态框
				isShow: false,
				content: "确定要关闭吗",
				confirmText:"确定",
			};
		},
		onLoad() {
			let pram = {
				expertId:this.expertId
			} 
			this.getOpenStatus(pram)
		},
		methods:{
			getOpenStatus(pram){
				API.registerOpenConsultOpen(pram).then(res =>{
					if(res.code === 200) {
						let {consultOpen,registerOpen} = res.result;
						this.consultOpen = consultOpen ? true : false;
						this.registerOpen = registerOpen ? true : false;
						// this.$forceUpdate();
						
					} else {
								uni.showToast({
									title: res.message,
									icon: "none"
								})
							}
						console.log('开关状态',res);
				})
			},
			isOpen(value){
				console.log('value',value);
				// let name = value.label
				if(value === '线上咨询'){
					API.consultOpen().then(res =>{
						if(res.code !== 200) {
								uni.showToast({
									title: res.message,
									icon: "none"
								})
							}
						console.log('线上咨询',res);
					})
					
				}else{
					if(this.registerOpen){
						console.log('只开',this.registerOpen);
						API.registerOpen().then(res =>{
							if(res.code !== 200) {
									uni.showToast({
										title: res.message,
										icon: "none"
									})
								}
							console.log(res);
							// this.registerOpen = true ;
						})
					}else{
						
						API.registerOpen().then(res =>{
							if(res.code == 99999) {
								this.content = res.message;
								// console.log('false时',this.registerOpen);
								this.isShow = true;
							} else {
								uni.showToast({
									title: res.message,
									icon: "none"
								})
							}
								console.log(res);
						})
					}
				}
			},
			// 确定修改
			confirmBtn(){
				API.forceCloseRegister().then(res =>{
					console.log('确定修改',res);
					if(res.code === 200){
						let pram = {
							expertId:this.expertId
						} 
						this.getOpenStatus(pram)
						// this.registerOpen = !this.registerOpen;
					}else{
						uni.showToast({
							title:res.message,
							icon:"none"
						})
					}
					this.isShow = false
				})
			},
			// 关闭模态框
			closeBtn() {
				this.isShow = false
				this.registerOpen = true;
				console.log('关闭模态框',this.registerOpen);
			},
			
		}
	}
</script>

<style lang="scss" scoped>
	.setup-content {
		background-color: #fff;

		.noborder{
			border: none !important;
		}

		.items {
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 110rpx;
			border-top: 1rpx #E3E3E3 solid;
			font-size: 30rpx;

			.label {
				width: 30%;
				font-family: PingFang SC;
				font-weight: bold;
				color: #333333;
			}

			.val {
				display: flex;
				align-items: center;
				font-family: PingFang SC;
				font-weight: 500;
				color: #999999;

				/deep/.u-iconfont {
					margin-left: 17rpx;
				}
			}

		}
	}
</style>
